package lucene.server.common.datasource;

import java.util.HashMap;

public class PoolConfig {

    private static HashMap<String, String> validateSql = new HashMap<>();
    static {
        validateSql.put("mysql", "select 1");
        validateSql.put("oracle", "select 1 from dual");
        validateSql.put("sqlserver", "select 1");
        validateSql.put("postgresql", "select 1");
        validateSql.put("db2", "select 1 from sysibm.sysdummy1");
        validateSql.put("h2", "select 1");
        validateSql.put("sqlite", "select 1");
        validateSql.put("derby", "select 1");
        validateSql.put("hsqldb", "select 1");
        validateSql.put("mssql", "select 1");
    }

    //数据库连接池的配置
    private static int poolInitSize = 1;
    private static int poolMaxSize = 20;
    //执行SQL最长时间
    private static long poolTimeout = 20000;
    //获取链接最长等待时间
    private static long poolWaitTimeout = 2000;

    //验证链接间隔时间
    private static long validateTimeMillis = 60000;


    public static String getValidateSql(String dbType){
        return validateSql.get(dbType.toLowerCase());
    }

    public static int getPoolInitSize() {
        return poolInitSize;
    }

    public static void setPoolInitSize(int poolInitSize) {
        PoolConfig.poolInitSize = poolInitSize;
    }

    public static int getPoolMaxSize() {
        return poolMaxSize;
    }

    public static void setPoolMaxSize(int poolMaxSize) {
        PoolConfig.poolMaxSize = poolMaxSize;
    }

    public static long getPoolTimeout() {
        return poolTimeout;
    }

    public static void setPoolTimeout(int poolTimeout) {
        PoolConfig.poolTimeout = poolTimeout;
    }

    public static long getPoolWaitTimeout() {
        return poolWaitTimeout;
    }

    public static void setPoolWaitTimeout(int poolWaitTimeout) {
        PoolConfig.poolWaitTimeout = poolWaitTimeout;
    }

    public static long getValidateTimeMillis() {
        return validateTimeMillis;
    }

    public static void setValidateTimeMillis(int validateTimeMillis) {
        PoolConfig.validateTimeMillis = validateTimeMillis;
    }
}
